package com.hc.langchain4j.config;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.pinecone.PineconeEmbeddingStore;
import dev.langchain4j.store.embedding.pinecone.PineconeServerlessIndexConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author : Henry
 * {@code CreateTime}: 2025-06-13 10:08
 * {@code Version}: 1.0
 */
@Configuration
public class EmbeddingStoreConfig {

    @Autowired
    private EmbeddingModel embeddingModel;

    @Bean
    public EmbeddingStore<TextSegment> embeddingStore() {
        // 创建向量存储
        EmbeddingStore<TextSegment> embeddingStore = PineconeEmbeddingStore.builder()
//                .apiKey(System.getenv("PINECONE_API_KEY"))
                .apiKey("pcsk_7RyZcP_JUF2EqfBdJKBocsY6VBwMYf2jp653SwJ68HysR1NiTWo3Az5hMYJh8JJ56JkPb7")
                // 如果指定的所有不存在，将创建一个新的索引
                .index("xiaozhi-index")
                // 如果指定的所有不存在，将创建一个新的索引空间
                .nameSpace("xiaozhi-namespace")
                .createIndex(PineconeServerlessIndexConfig.builder()
                        .cloud("AWS")
                        // 指定索引所在的 AWS 区域未 us-east-1
                        .region("us-east-1")
                        // 指定索引的向量维度，该维度与 embeddingModel 生成的向量维度相同
                        .dimension(embeddingModel.dimension())
                        .build())
                .build();
        return embeddingStore;
    }
}
